﻿
//function ShowDBSourceWin_Button() {
//    alert("hell0");
//    var strReturn = window.showModalDialog("frame.htm", "ConfigDataSource.aspx", "font-size:10px;dialogWidth:650px;dialogHeight:560px;status=no;center=yes;resizable=no;");
//    if (strReturn == "Y") {
//        document.getElementById("btnRun").click();
//    }

//}
//    //显示文本采集页面
//function ShowTestIn_Button() {
//    alert("hello");
//        var strReturn = window.showModalDialog("frame.htm", "SJCJTextTest.aspx", "font-size:10px;dialogWidth:650px;dialogHeight:560px;status=no;center=yes;resizable=no;");
//        if (strReturn == "Y") {
//            alert("数据导入成功");
//        }

//    }

    //添加farpoint隐藏列,设置隐藏列宽度为0,再隐藏客户端控件
    function FarpointControlInit() {
        FpSpread1_viewport2.style.display = "none"; // 具体数据 
        FpSpread1_fcht.style.display = "none"; //数据表头
    }

    //打开一个类似Form的对话框,计算界面
    function OpenFormWindow(x, y) {

        //显示待隐藏的窗口
        var ppObj = document.getElementById("ppWindow");
        ppObj.style.display = '';
        ppObj.style.visibility = 'visible';
        //设置窗口显示的起点位置
        ppObj.style.left = window.screen.availWidth / 2 - 200;   //x +10;
        ppObj.style.top = window.screen.availHeight / 2 - 100;  // y + 300;

        ObjectFlashIn(ppObj, 100, false, 5);
    }

    //关闭一个类似Form的对话框
    function CloseFormWindow() {
        //关闭对话框
        var ppObj = document.getElementById("ppWindow");
        ppObj.style.display = 'none';
        ObjectFlashOut(ppObj, 0, false, 5);
    }

    function SpreadActiveRowChanged() {
        var ActiveRowIndex = FpSpread1.ActiveRow;
        if (ActiveRowIndex > -1) {
            var FieldCount = document.all["FieldCount"].value;
            k = 0;
            for (i = 0; i < FieldCount; i++) {
                var txtname = "txt_" + i;
                if (document.all[txtname]) {
                    var h = document.all[txtname];

                    if ((h.attributes["type"] != undefined) && (h.attributes["type"].value == "checkbox")) {
                        var ivalue = FpSpread1.GetValue(ActiveRowIndex, k++);
                        //  alert(ivalue)
                        if (ivalue == "true")
                            h.checked = 1;
                        else
                            h.checked = 0;

                    }
                    else {
                        h.value = FpSpread1.GetValue(ActiveRowIndex, k++);

                    }

                }
            }

            var FpSpread = document.all["FpSpread1_viewport"];

            for (i = 0; i < FpSpread.rows.length; i++) {
                if (i == ActiveRowIndex) {
                    FpSpread.rows(i).style.backgroundColor = 'Linen';
                }
                else
                    FpSpread.rows(i).style.backgroundColor = 'white';
            }

            var FpSpread2 = document.all["FpSpread1_viewport2"];

            if (FpSpread2 == "undefined" || FpSpread2 == null)
                return;
            else {
                for (i = 0; i < FpSpread2.rows.length; i++) {
                    if (i == ActiveRowIndex) {
                        FpSpread2.rows(i).style.backgroundColor = 'Linen';
                    }
                    else
                        FpSpread2.rows(i).style.backgroundColor = 'white';
                }
            }
        }
    }

    function AddNewData() {
        var i = FpSpread1.GetRowCount();

        var FieldCount = document.all["FieldCount"].value;
        FpSpread1.Add(i, 1);
        FpSpread1.SetActiveCell(i, 0);
        FpSpread1.ActiveRow = i;
        SpreadActiveRowChanged();

        for (i = 0; i < FieldCount; i++) {
            if (document.all[txtname]) {
                var txtname = "txt_" + i;
                var input = document.getElementById(txtname);
                if (input.getAttribute('disabled')) {
                    input.removeAttribute('disabled');
                }
            }
        }
    }
    //输入框控制只能够输入数字
    function onlyNum(obj) {
        //控制多个小数点的输入       
        var objs = obj.value.split(".");
        if (objs.length == 2 && event.keyCode == 190)
            event.returnValue = false;
        else {
            //控制只输入数字和小数点  
            if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 46 || event.keyCode == 190 || event.keyCode == 110 || event.keyCode == 37 || event.keyCode == 39))
                event.returnValue = false;
        }
    }
    //表单数据与网格动态绑定
    function BindDataToGrid(obj, k, DataType) {

        var ActiveRowIndex = FpSpread1.ActiveRow;
        if (obj.value != "") {
            // alert(obj.checked);
            if (obj.type != 'checkbox') {
                if (DataType == "N") {
                    FpSpread1.SetValue(ActiveRowIndex, k, parseFloat(obj.value), "");
                }
                else {
                    FpSpread1.SetValue(ActiveRowIndex, k, obj.value, "");
                }
            }
            else {
                if (obj.checked)
                    FpSpread1.SetValue(ActiveRowIndex, k, "true", "");
                else
                    FpSpread1.SetValue(ActiveRowIndex, k, "false", "");
            }
        }
        else {
            FpSpread1.SetValue(ActiveRowIndex, k, obj.value, "");
        }
    }


    var rowValue = 0;  //行计数器
    var colValue = 0;  //列计数器
    var isChange = false;
    var value_temp;
    var DataFrame = null;
    var x = 0;
    var y = 0;
    var ActiveRowIndex = -1;
    var ActiveColIndex = -1;

    function window.onload() {
        var spread = document.all("FpSpread1");
        if (spread != null) {
            spread.onDataChanged = dataChanged;
            spread.onSelectionChanged = selectChanged;
            spread.onEditStart = spreadEditStart;
            spread.ondblclick = spreaddblclick;
        }
        var spread_message = document.all("FpSpread_Error");
        if (spread_message != null) {
            spread_message.onSelectionChanged = selectChanged_message;
        }
    }
    //双击待计算行,弹出计算界面
    function spreaddblclick() {
        ActiveColIndex = FpSpread1.ActiveCol;
        ActiveRowIndex = FpSpread1.ActiveRow;

        if (ActiveColIndex == "-1" || ActiveRowIndex == "-1") {
            return;
        }
        var BDM = document.all["BDM"].value;
        var FieldCount = document.all["hidVisibleFieldCount"].value;

        if (BDM == "" || FieldCount == 0) {
            return;
        }
        else {
            for (i = 0; i < FieldCount; i++) {
                if (ActiveColIndex == i) {

                    //  x = event.x;
                    //   y = event.y;
                    //获取待计算参数
                    //  PageMethods.GetDataFieldFactor(h.title + "," + h.zdid, GetDataFieldFactorList);


                    var hidPop = document.all["hidPopField"];
                    if (hidPop) {
                        var Pop = hidPop.value;
                        if (Pop.indexOf(',' + (i + 1).toString() + ':') >= 0) {
                            //Pop形如  ,9:TEXT-YC_TEXT,8:FILE-YC_FILE,
                            var pTmp = Pop.substring(1, Pop.length - 1);
                            var split1 = pTmp.split(',');
                            for (m = 0; m < split1.length; m++) {
                                var split2 = split1[m].split(':');
                                if (split2[0] == (i + 1).toString()) {
                                    ShowSubWin(split2[1]);
                                    return;
                                }
                            }

                            // alert(Pop);
                        }
                        else
                            return;

                    }
                    else
                        return;

                }
            }
        }
    }

    //以下两个函数ShowSubWin 和 ShowSubWin_Button的功能是一样的，都是处理弹出窗口录入，ShowSubWin是在FARPOINT单元格中鼠标双击时触发，ShowSubWin_Button是FORM表单上的对应按钮触发
    function ShowSubWin(p_Type) {
        var oldValue = FpSpread1.GetValue(ActiveRowIndex, ActiveColIndex);
        var split1 = p_Type.split('-'); //TEXT-YC_TEXT
        var strType = split1[0];
        var strSubTab = split1[1];
        var strColName = split1[2];
        var strPage;
        if (strType == "TEXT") {
            strPage = "CommonDataAdmin_TEXT.aspx";
        }
        else if (strType == "FILE") {
            strPage = "CommonDataAdmin_FILE.aspx";
        }
        //alert(strPage + "?SUBTAB=" + strSubTab + "&ID=" + oldValue);
        var strReturn = showModalDialog("frame.htm", strPage + "?SUBTAB=" + strSubTab + "&ID=" + oldValue + "&COLNAME=" + strColName, "font-size:10px;dialogWidth:510px;dialogHeight:330px;status=no;center=yes;resizable=no;");
        if ((strReturn == "N/A") || (strReturn == undefined)) {

        }
        else {
            FpSpread1.SetValue(ActiveRowIndex, ActiveColIndex, strReturn, ""); // FpSpread1.SetActiveCell(ActiveRowIndex, ActiveColIndex - 1);

        }

    }

    function ShowSubWin_Button(obj, k, popWin) {
        var hid = document.getElementById(obj);
        var oldValue = hid.value;
        // alert(oldValue);
        var split1 = popWin.split('-'); //TEXT-YC_TEXT
        var strType = split1[0];
        var strSubTab = split1[1];

        var strPage;
        if (strType == "TEXT") {
            strPage = "CommonDataAdmin_TEXT.aspx";
        }
        else if (strType == "FILE") {
            strPage = "CommonDataAdmin_FILE.aspx";
        }
        //alert(strPage + "?SUBTAB=" + strSubTab + "&ID=" + oldValue);
        var strReturn = showModalDialog("frame.htm", strPage + "?SUBTAB=" + strSubTab + "&ID=" + oldValue, "font-size:10px;dialogWidth:510px;dialogHeight:330px;status=no;center=yes;resizable=no;");
        if ((strReturn == "N/A") || (strReturn == undefined)) {

        }
        else {
            hid.value = strReturn;
            var ActiveRowIndex = FpSpread1.ActiveRow;
            FpSpread1.SetValue(ActiveRowIndex, k, strReturn, "");

        }

    }

    function btnOpen(obj, k, popWin) {
        ShowSubWin_Button(obj, k, popWin);
        //  alert(obj + "  " + k + "  " + popWin);

    }



    //双击待计算行,弹出计算界面
    function GetDataFieldFactorList(obj) {
        if (obj == "")
            return;
        else {
            document.all["ppWindow1"].innerHTML = obj;
            OpenFormWindow(x, y);
        }
    }
    //计算待计算字段数值
    function btnConfrim(rowcount, fieldid) {

        if (rowcount == "" || fieldid == "") {
            return;
        }
        else {
            var rows = parseInt(rowcount);
            var NullList = "";
            for (i = 0; i < rows; i++) {
                var txtname = "zb_lab_" + i;
                var h = document.all[txtname];
                if (h.value == "") {
                    if (NullList == "") {
                        NullList = h.title;
                    }
                    else {
                        NullList = NullList + "," + h.title;
                    }

                }
            }
            if (NullList != "") {
                alert(NullList + "值不能够为空,请先填写!");
                return;
            }
            var zbdm = "";
            var zbsz = "";
            for (i = 0; i < rows; i++) {
                var txtname = "zb_lab_" + i;
                var h = document.all[txtname];
                if (zbdm == "") {
                    zbdm = h.name;
                }
                else {
                    zbdm = zbdm + "," + h.name;
                }

                if (zbsz == "") {
                    zbsz = h.value;
                }
                else {
                    zbsz = zbsz + "," + h.value;
                }
            }
            //获取待计算参数
            PageMethods.ComunicateDataField(fieldid + "#" + zbdm + "#" + zbsz, GetComunicateResult);
        }
    }
    function GetComunicateResult(result) {
        if (confirm("计算结果为:" + result + "\r\n" + "你确定要应用该计算结果吗?")) {
            FpSpread1.SetValue(ActiveRowIndex, ActiveColIndex, result, "");

            var FpSpread2 = document.all["FpSpread1_viewport2"];

            var fkcols = 0;
            if (FpSpread2 == "undefined" || FpSpread2 == null)
                fkcols = 0;
            else {
                fkcols = FpSpread2.cols;
            }

            var FpSpread = document.all["FpSpread1_viewport"];
            for (i = 0; i < FpSpread.rows.length; i++) {
                if (i == ActiveRowIndex) {
                    FpSpread.rows(i).cells[ActiveColIndex - fkcols].style.color = 'Blue';
                }
            }

            CloseFormWindow();
        }
    }
    //关闭计算界面
    function btnCancel() {
        CloseFormWindow();
    }
    function dataChanged() {
        var btncacel = document.all("ImBtn_cancle");
        var btnsave = document.all("ImBtn_save");
        SetEnable(btncacel, "true");
        SetEnable(btnsave, "true");
        //--------------------------------------将改变的数据放入固定列
        /*
        var rowValue=0;  //行计数器
        var colValue=0;  //列计数器
        var rowValueCount=0;  //已复制的行数
        var colValueCount=0;  //已复制的列数
        */
        //-------------------------------------------------------
        var iMess = window.clipboardData.getData("Text");
        var countrows = 1;
        var countcols = 1;
        var maxcols = 1;
        if (iMess != null && iMess != "") {
            for (var i = 0; i < iMess.length; i++) {
                var split = iMess.substring(i, i + 1);
                switch (split) {
                    case "\r":
                        if (countcols > maxcols)
                            maxcols = countcols;
                        countcols = 0;
                        if (i < iMess.length - 3)
                            countrows = countrows + 1;
                        break;
                    case "\t":
                        countcols = countcols + 1;
                        break;

                }
            }
        }
        countcols = maxcols;
        //获取第几列数据需要设置为固定列
        var spread = document.all("FpSpread1");
        var f = document.Form1;

        var span = document.all("FpSpread1_rowHeader");
        var table = span.firstChild;

        var row = spread.ActiveRow;
        var col = spread.ActiveCol;

        var fixcol = f.hid_fixcolumn.value;
        var Values = fixcol.split("#");
        for (var i = 0; i < Values.length; i++) {
            if (spread.ActiveCol + colValue == Values[i] && Values[i] != "") {
                var ModifyValue = spread.GetValue(spread.ActiveRow + rowValue, spread.ActiveCol + colValue);

                table.rows(spread.ActiveRow + rowValue + 1).cells(i + 1).innerText = ModifyValue;
                break;
            }
        }
        colValue = colValue + 1;
        if ((colValue % countcols) == 0) {
            colValue = 0;
            rowValue = rowValue + 1;
        }
        //修改数据后设置颜色
        var view_row = document.all("FpSpread1_view");
        var table_row = view_row.firstChild;
        var tr_row = table_row.rows(row + 1);
        //tr_row.style.backgroundColor = "LightGreen";
        //            if (tr_row.style.backgroundColor != "LightGreen" && tr_row.style.backgroundColor != "Orange")
        //                tr_row.style.backgroundColor = "LightGoldenrodYellow";

    }

    //即使在通一行不同CELL间切换也会触发此事件
    function selectChanged() {

        SpreadActiveRowChanged();

        var btnupdate = document.all("ImBtn_update");
        var btncopy = document.all("ImBtn_copy");
        var btncut = document.all("ImBtn_cut");
        var btnpaste = document.all("ImBtn_paste");
        var btndelete = document.all("ImBtn_delete");
        var btnadd = document.all("ImBtn_add");
        var btnsave = document.all("ImBtn_save");
        var btnpasteadd = document.all("ImBtn_pasteadd");

        SetEnable(btnupdate, "true");
        SetEnable(btncopy, "true");
        SetEnable(btncut, "true");
        SetEnable(btnpaste, "true");
        SetEnable(btnsave, "true");
        if (btnadd.Enable == "true") {
            SetEnable(btndelete, "true");
            SetEnable(btnpasteadd, "true");
        }
        else {
            SetEnable(btndelete, "false");
            SetEnable(btnpasteadd, "false");
        }
        //----------------------------------------------设置固定列
        rowValue = 0;  //行计数器
        colValue = 0;  //列计数器

        //add by qiuban 20061017
        //为批量删除数据,客户端记录所选中的行和行数
        var rg = FpSpread1.GetSelectedRange();
        document.all["Selectrows"].value = rg.row + "#" + rg.col + "#" + rg.rowCount + "#" + rg.colCount;
    }
    function spreadEditStart() {

        var btncopy = document.all("ImBtn_copy");
        var btncut = document.all("ImBtn_cut");
        var btnpaste = document.all("ImBtn_paste");
        var btndelete = document.all("ImBtn_delete");
        var btnpasteadd = document.all("ImBtn_pasteadd");

        SetEnable(btncopy, "false");
        SetEnable(btncut, "false");
        SetEnable(btnpaste, "false");
        SetEnable(btndelete, "false");
        //  SetEnable(btnpasteadd,"false") ;

    }
    function selectChanged_message() {

        if (document.all["hid_activesheet"].value == "删除数据表") {
            var rg = FpSpread_Error.GetSelectedRange();

            document.all["hid_delselect"].value = rg.row + "#" + rg.col + "#" + rg.rowCount + "#" + rg.colCount;
            window.status = rg.row + "#" + rg.col + "#" + rg.rowCount + "#" + rg.colCount;
            //------------------------------------
            var bdelreturn = document.all("ImBtn_delreturn");
            SetEnable(bdelreturn, "true");
        }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////dhn

    function SelectChange(sender) {
    }
    function Paste() {

        var f = document.Form1;

        if (event.srcElement.id == "ImBtn_key") {
            CheckKey();
        }
        if (event.srcElement.id == "ImBtn_update") {
            isChange = false;

        }
        if (event.srcElement.id == "ImBtn_cancle") {
            isChange = false;

        }
        if (event.srcElement.id == "ImBtn_add") {
            isChange = false;
            AddNewData();
        }

        if (event.srcElement.id == "ImBtn_delete") {
            isChange = false;
            if (event.srcElement.Enable == "true")
                if (confirm("你确定要删除记录吗?")) {
                    // var spread = document.all("EditGrid0");  
                    //  spread.Delete();
                    __doPostBack('ImBtn_delete', '');
                }
        }
        if (event.srcElement.id == "ImBtn_pasteadd") {
            isChange = false;
            var Imgbtn = document.all("ImBtn_pasteadd");
            if (Imgbtn.Enable == "true") {
                f.hidKid.value = window.clipboardData.getData("Text");
                __doPostBack('LinkButton1', '');
            }

        }
        if (event.srcElement.id == "ImBtn_save") {
            isChange = false;
        }
        if (event.srcElement.id == "ImBtn_copy") {
            var spread = document.all("FpSpread1");
            spread.Copy();

        }
        if (event.srcElement.id == "ImBtn_cut") {
            var spread = document.all("FpSpread1");
            spread.Clear();
        }
        if (event.srcElement.id == "ImBtn_paste") {
            var spread = document.all("FpSpread1");
            spread.Paste();
        }
        if (event.srcElement.id == "ShowTip")//
        {
            var spread = document.all("FpSpread1");
            spread.SetShowPrikeyTip(false);
        }

    }

    /*
    函数作用: 利用DIV的特性,创建一个满屏的窗口
    参数: 
    argWindowID: 窗口的ID
    argOpacity: 窗口的不透明度(取值范围: 0--100. 0为完全透明, 100为完全不透明.)
    argBackColor: 窗口的背景色
    argZ_Index: 窗口的第三维高度
    */
    function CreateDivFullWindow(argWindowID, argOpacity, argBackColor, argZ_Index) {
        return
        "<div"
                    + " id=\"" + argWindowID + "\""
                    + " style=\"position: absolute; position: absolute; left: 0px; top: 0px;"
                    + " filter: alpha(opacity:" + argOpacity + ");"
                    + " height: " + screen.availHeight + "px";
+" width: " + screen.availWidth + "px";
+" background-color: " + argBackColor + ";"
                    + " z-index: " + argZ_Index + "; \"></div>";
    }
    /* 函数作用: 利用CSS的Filter滤镜实现淡入的效果
    参数:
    argObject: 要显示的对象
    argOpacity: 对象的不透明度(取值范围: 0--100. 0为完全透明, 100为完全不透明.)
    argIsFlash: 是否需要动画显示
    argFlashSpeed: 对象显示的速度
    argTimeInterval: 对象显示的时间间隔
    */
    function ObjectFlashIn(argObject, argOpacity, argIsFlash, argFlashSpeed, argTimeInterval) {
        if ((argObject.filters.alpha.opacity < argOpacity) && (argIsFlash)) {
            argObject.filters.alpha.opacity += argFlashSpeed;
            window.setTimeout("ObjectFlashIn(" + argObject.id + ", " + argOpacity + ", " + argIsFlash + ", " + argFlashSpeed + ")", argTimeInterval);
        }
        else {
            argObject.filters.alpha.opacity = argOpacity;
            argObject.style.visibility = "visible";
        }
    }
    /* 利用CSS的Filter滤镜实现淡出的效果
    参数:
    argObject: 要淡出的对象
    argOpacity: 对象的不透明度(取值范围: 0--100. 0为完全透明, 100为完全不透明.)
    argIsFlash: 是否需要动画淡出
    argFlashSpeed: 对象淡出的速度
    argTimeInterval: 对象淡出的时间间隔
    */
    function ObjectFlashOut(argObject, argOpacity, argIsFlash, argFlashSpeed, argTimeInterval) {
        if ((argObject.filters.alpha.opacity > argOpacity) && (argIsFlash)) {
            argObject.filters.alpha.opacity -= argFlashSpeed;
            window.setTimeout("ObjectFlashOut(" + argObject.id + ", " + argOpacity + ", " + argIsFlash + ", " + argFlashSpeed + ")", argTimeInterval);
        }
        else {
            argObject.filters.alpha.opacity = argOpacity;
            argObject.style.visibility = "hidden";
        }
    }

    function ShowText() {

        alert(1);
    }


    //选择忽略主键冲突
    function CheckKey() {
        var chkKey = document.all("chkIgnoreKeyConflict");
        chkKey.checked = !chkKey.checked;
    }
